cd FigureA13
use "$path\datasets\rd_dataset.dta", clear


gen sum_elected_female_ex_last=sum_elected_female
replace sum_elected_female_ex_last=sum_elected_female_ex_last-1 if elected_women==1
gen base_effect=(sum_elected_female_ex_last/(sum_elected_hcd))
gen base_effect_elected_women = base_effect*elected_women
gen base_effect_margin_1=base_effect*margin_1
gen base_effect_inter_1=base_effect*margin_1*elected_women





local depvar "ch_total_child_places_pc"



****************************************************************************************************

bandwidth_and_weights, depvar(`depvar') var(margin_1)  bwmethod(CCT) kernel(tri) degree(1) number_of_elec(num_of_obs)
ivreg2 `depvar' elected_women base_effect base_effect_elected_women  margin_1 inter_1  base_effect_margin_1 base_effect_inter_1  if abs(margin_1)<$bw_opt  [pw=weight] , r cluster(gkz ) partial(margin_1 inter_1 base_effect_margin_1 base_effect_inter_1)



interact_graph  elected_women base_effect base_effect_elected_women, xtitle("Share of women")
graph export figureA13.pdf, replace


****************************************************************************************************

preserve
use "$path\datasets\individual_data.dta", clear

bysort gkz jahr: egen sum_elected_hcd=sum(elected)

gen elected_women= elected*female

bysort gkz jahr: egen sum_all_female=sum(female)
bysort gkz jahr: egen sum_elected_female=sum(female) if elected==1
bysort gkz jahr (sum_elected_female): replace sum_elected_female=sum_elected_female[1]
gen tot_share_women_elected=(sum_elected_female/sum_elected_hcd)
bysort gkz jahr: keep if _n==1



sum tot_share_women_elected, det

local p5 = r(p5)
local p25 = r(p25)
local p50 = r(p50)
local p75 = r(p75)
local p95 = r(p95)

gen a=.
drop if _n>100
gen xaxis= ((_n)/100)
graph addplot  line a xaxis  , xline(`p5', lcolor(gray) lpattern(shortdash)) xline(`p25', lcolor(gray) lpattern(shortdash)) xline(`p50', lcolor(gray)  lpattern(shortdash)) xline(`p75',lcolor(gray)  lpattern(shortdash))  xline(`p95',lcolor(gray)  lpattern(shortdash)) ytitle("Marginal effect") xtitle("Share of women")  

restore

****************************************************************************************************

graph export figureA13.pdf, replace
cd ..
